import oracle.jdbc.driver.OracleConnection;

import org.apache.log4j.Logger;


public class DBMS_STREAMS_MESSAGEUtil extends OracleAQ {

	private Logger logger = Logger.getLogger( AQEnqueue.class);
	
	public DBMS_STREAMS_MESSAGEUtil() {}
	
	public DBMS_STREAMS_MESSAGEUtil( String user, String password, String host, String port, String sid) {
		super( user, password, host, port, sid);
	
	}
	
	public DBMS_STREAMS_MESSAGEUtil( String user, String password, String url) {
		super( user, password, url);
	
	}
	
	
	public void ENQUEUE( OracleConnection conn, String queue_Name, oracle.sql.ANYDATA payload) {
		
		try {
			this.conn = conn;
			this.doUpdateDatabase( "BEGIN DBMS_STREAMS_MESSAGING.ENQUEUE( queue_name=>'" + queue_Name + "', payload=>'"
					+ payload + "'); END; ");
			
		} catch( Exception e) {
			logger.error( e.getMessage());
			
		}
		
	}
	
	public void DEQUEUE( OracleConnection conn, String queue_Name, String streams_Name) {
		
		try {
			this.conn = conn;
			this.doUpdateDatabase( "BEGIN DBMS_STREAMS_MESSAGING.DEQUEUE( queue_name=>'" + queue_Name + "', streams_name=>'"
					+ streams_Name + "', dequeue_mode=>'REMOVE', navigation=>'NEXT MESSAGE'); END; ");
			
		} catch( Exception e) {
			logger.error( e.getMessage());
			
		}
		
	}
	
	public static void main( String[] argv) {
		
		DBMS_STREAMS_MESSAGEUtil test = new DBMS_STREAMS_MESSAGEUtil( "strmadmin", "streams", "192.168.0.98", "1521", "bizteco");
		
		OracleConnection conn = test.connect();
		
		
		
//		test.ENQUEUE( conn, "OGG_QUEUE", "abc".getBytes());
		test.DEQUEUE( conn, "OGG_QUEUE", null);
		
//		da.createQueueTable( conn, "OGG_TABLE", "SYS.ANYDATA", "10.0");
//		da.createQueue( conn, "OGG_QUEUE", "strmadmin.OGG_TABLE");
//		da.startQueue( conn, "OGG_QUEUE");
	}
}
